package com.yt.fras.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;

/**
 * ClassName:SwaggerConfig
 * Package:com.yt.fras.config
 * Description:
 * 接口文档配置
 *
 * @date:2021/8/15 12:48
 * @author:yt
 */
@Configuration
public class SwaggerConfig {
    /**
     * 配置docket以配置Swagger具体参数
     *
     * @return
     */
    @Bean
    public Docket docket(Environment environment) {
        Profiles of = Profiles.of("dev", "test", "prod");
        // 判断当前是否处于该环境
        // 通过 enable() 接收此参数判断是否要显示
        boolean b = environment.acceptsProfiles(of);
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo()).groupName("fras")
                .enable(b)
                .ignoredParameterTypes(HttpSession.class, HttpServletRequest.class, HttpServletResponse.class)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yt.fras"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        //联系人信息
        Contact contact = new Contact("杨涛", "http://47.101.182.207/", "1456858781@qq.com");
        return new ApiInfo("FRAS", "人脸识别考勤系统", "v1.0", "http://47.101.182.207/", contact, "Apache 2.0 许可", "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList<>());
    }


}
